import java.util.Scanner;

public class demo2 {
    public ListNode reverseList1(ListNode head) {
        if(head==null||head.next==null)return head;
        ListNode newhead=null;//设置一个空节点去首次连接 便于操作
        ListNode cur=head;

        while(cur!=null){
            ListNode ncur=cur.next;
            cur.next=newhead;
            newhead=cur;
            cur=ncur;
        }
        return newhead;
    }
    //使用递归翻转链表
    public ListNode reverseList(ListNode head){
       return reverse(head,null);
    }
    public ListNode reverse(ListNode cur,ListNode nhead){
        reverse(cur.next,nhead);
       if(cur==null)return nhead;
        return nhead;
    }
}
